/**
 * @author Helio
 */
var SaleStatusTopView = Ext.extend(BasicPanel,{
		
	initlize : function() {
		
		if(!this.detailsGrid) {
						
			this.detailsStore = new Ext.data.Store({
			    proxy: new Ext.data.MemoryProxy(this.detailsJson),
			    //remoteSort:true,
			    reader: new Ext.data.JsonReader({
					root: 'products',
					remoteSort: true,
			        fields: ['code','name', 'number', 'unit', 'star', 'amount']
			    })
			});
						
			// create the grid
			this.detailsGrid = new Ext.grid.GridPanel({
				store: this.detailsStore,
				title: '销售排行榜',
				columns: [new Ext.grid.RowNumberer(), {
					header: "商品编号",
					dataIndex: 'code',
					width: 80
				}, {
					header: "商品名称",
					dataIndex: 'name'
				}, {
					header: "销售数量",
					dataIndex: 'number',
	           		align: 'right',
					width: 80
				}, {
					header: "单位",
					dataIndex: 'unit',
					width: 45
				}, {
					header: "销售总额",
					dataIndex: 'amount',					
	           		align: 'right',
	           		width: 80
				}, {
					header: '<img src="'+SALE.img.STAR_URL+'"/>',
	           		align: 'center',
	           		dataIndex: 'star',
	           		width: 20,
	           		renderer: SALE.Utils.starRenderer.createDelegate(this)
				}],	
				
				viewConfig: {
			        forceFit: true,
					enableRowBody:true,
		            showPreview:true
			    },
		
				loadMask: true,
				stripeRows: true,
				border: false,
				autoExpandColumn: 'name',
				layout: 'fit'
			});
		}		
	},
	
	initlizeDataHandler : function(resultJson) {
		this.detailsJson['products'] = resultJson.products;
		this.detailsStore.load({params:{start:0, limit:25}});
	},
	
	getCorePanel : function() {
		if (!this.detailsGrid) {
			this.initlize();
			SALE.Action.searchSaleStatusTop(this.initlizeDataHandler.createDelegate(this));
		}
		return this.detailsGrid;
	}
});

SaleStatusTopView.showStatusPanel = function(){
	var  statusView = new SaleStatusTopView();
	
	SALE.App.showOperateTabPanel(statusView.getCorePanel(), "销售排行榜");
}